local yuanhu = fk.CreateSkill{
    name = "XD__yuanhu"
}
Fk:loadTranslationTable{
    ["XD__yuanhu"] = "援护",
    [":XD__yuanhu"] = "一轮开始时，你可以摸一张牌并将一张牌交给一名其他角色（若为装备牌，其可以使用之），然后你可以弃置攻击范围内含有其的一名角色区域里的一张牌。本轮内，当前者成为【杀】的目标时，你可以将此【杀】转移给你。",
    ["#XD__yuanhu"] = "援护：将一张牌交给一名其他角色（若为装备牌，其可以使用之）",
    ["#XD__yuanhu-use"] = "援护：你可以使用%arg",
    ["#XD__yuanhu-choose"] = "援护：你可以弃置攻击范围内有 %dest 的一名角色区域里的一张牌",
    ["#XD__yuanhu-discard"] = "援护：弃置 %dest 区域里的一张牌",
    ["#XD__yuanhu-invoke"] = "援护：你可以将 %src 对 %dest 使用的%arg转移给你",
    ["@[chara]XD__yuanhu-round"] = "援护",
}

yuanhu:addEffect(fk.RoundStart, {
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(yuanhu.name)
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        player:drawCards(1, yuanhu.name)
        if player:isNude() then return end
        local tos, cards = room:askToChooseCardsAndPlayers(player, {
            max_card_num = 1,
            max_num = 1,
            min_card_num = 1,
            min_num = 1,
            targets = room:getOtherPlayers(player),
            skill_name = yuanhu.name,
            prompt = "#XD__yuanhu",
            cancelable = false,
        })
        if #tos > 0 and #cards > 0 then
            local to = tos[1]
            room:setPlayerMark(player, "@[chara]XD__yuanhu-round", to.id)
            room:obtainCard(to, cards, false, fk.ReasonGive, player, yuanhu.name)
            if Fk:getCardById(cards[1]).type == Card.TypeEquip then
                room:askToUseRealCard(to, {
                    pattern = {cards[1]},
                    skill_name = yuanhu.name,
                    prompt = "#XD__yuanhu-use:::"..Fk:getCardById(cards[1]):toLogString(),
                })
            end
            local targets = table.filter(room.alive_players, function (cp)
                return cp:inMyAttackRange(to) and not cp:isAllNude()
            end)
            local currents = room:askToChoosePlayers(player, {
                targets = targets,
                max_num = 1,
                min_num = 1,
                skill_name = yuanhu.name,
                prompt = "#XD__yuanhu-choose::"..to.id,
            })
            if #currents > 0 then
                local current = currents[1]
                local card = room:askToChooseCard(player, {
                    target = current,
                    flag = "hej",
                    skill_name = yuanhu.name,
                    prompt = "#XD__yuanhu-discard::"..current.id,
                })
                room:throwCard(card, yuanhu.name, current, player)
            end
        end
    end,
})

yuanhu:addEffect(fk.TargetConfirming, {
    anim_type = "support",
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return player:getMark("@[chara]XD__yuanhu-round") == target.id and data.card.trueName == "slash" and
        data.to ~= player and not data.from:isProhibited(player, data.card)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if room:askToSkillInvoke(player, {
            skill_name = yuanhu.name,
            prompt = "#XD__yuanhu-invoke:"..data.from.id..":"..data.to.id..":"..data.card:toLogString(),
        }) then
            event:setCostData(self, {tos = {data.to}})
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        data:cancelTarget(data.to)
        data:addTarget(player)
    end,
})

return yuanhu